*  FILE NAME: PURC_DSP.PRG
*  BY: NURJADI PURNAMA
*  DATE: May 31, 1996
*  DESC:
*  CALLED BY:
*  DATA FILES:
CLEA
SET PROC TO SOSPRO
DR='N:'
F1='SUPPLIER'
F2='PUR_DRUG'
F3='PUR_DISP'
F4='DRUGS'
F5='DISPOS'
DO ADDRESSC
SUPPCOD=SPACE(4)
ORDNBER=SPACE(4)
SELE 1
SET EXCLU OFF
USE &DR&F1
SELE 2
SET EXCLU OFF
USE &DR&F2
SELE 3
SET EXCLU OFF
USE &DR&F3
SELE 4
SET EXCLU OFF
USE &DR&F4 INDEX &DR&F4
SELE 5
SET EXCLU OFF
USE &DR&F5 INDEX &DR&F5
PR=0

SELE 1
LOCATE FOR ORDR_N_Y_P=.T.  .AND. .NOT. EOF()
DO WHILE .T.
   IF FOUND()
      PR=PR+1
      SUPPCOD=SUPP_CODE
      SUPPNAM=SUPP_NAME
      SUPPADD1=SUPP_ADD1
      SUPPADD2=SUPP_ADD2
      SUPPCITY=SUPP_CITY
      SUPPCOUNT=SUPP_COUNT
      SUPPTEL=SUPP_TEL1
      SUPPFAX=SUPP_FAX
      FREEP=AEA_COMP
      SUPPTELEX=SUPP_TELEX
      CONPER=CONTACT_P
      MPPN=PPN
      PAYTERM=TERM_PAYMT
      
      PR=PR+1
      SUPPCOD=SUPP_CODE
      SUPPNAM=SUPP_NAME
      SUPPADD1=SUPP_ADD1
      SUPPADD2=SUPP_ADD2
      SUPPCITY=SUPP_CITY
      SUPPCOUNT=SUPP_COUNT
      SUPPTEL=SUPP_TEL1
      SUPPFAX=SUPP_FAX
      FREEP=AEA_COMP
      SUPPTELEX=SUPP_TELEX
      CONPER=CONTACT_P
      MPPN=PPN
      PAYTERM=TERM_PAYMT
      clea
      @  0, 00 SAY AEANAME
      @  1, 00 SAY AEAADDR
      @  2, 24 SAY 'P U R C H A S E  O R D E R'
      @  3, 61 say 'DATE : '+DTOC(DATE())
      @  4,  0 SAY 'SUPPLIER : '+SUPPNAM
      @  5,  0 SAY "ADDRESS  : "+SUPPADD1
      @  6, 12 SAY SUPPADD2
      @  7,  0 say repl('=',80)
      @  8,  0 SAY 'ITM'
      @  8,  4 say 'PRODUCT'
      @  8, 23 SAY 'TYPE'
      @  8, 33 SAY 'PACK'
      @  8, 41 SAY ' QTY.'
      @  8, 50 SAY 'UNT PRICE'
      @  8, 61 SAY "DISC."
      @  8, 70 SAY "NET PRICE"
      @  9,0 say repl('-',80)
      store 0 to ttl1,ttl2,ttl3,ttl4,ttl5
      ULANG='N'
      CNT=0
      TTL=0
      BR=0
      ITM=0
      ADA2=.F.
      ADA3=.F.
      SELE 2
      GO TOP
      LOCATE FOR SUPP_CODE=SUPPCOD .AND. .NOT. ORDR_PRINT .AND. .NOT. EOF()
      DO WHILE .T.
         IF FOUND()
            ADA2=.T.
            cnt=cnt+1
            CONTINUE
            LOOP
         ELSE
            EXIT
         ENDIF
      ENDDO
      SELE 3
      GO TOP
      LOCATE FOR SUPP_CODE=SUPPCOD .AND. .NOT. ORDR_PRINT .AND. .NOT. EOF()
      DO WHILE .T.
         IF FOUND()
            ADA3=.T.
            cnt=cnt+1
            CONTINUE
            LOOP
         ELSE
            EXIT
         ENDIF
      ENDDO
      declare fild[cnt]
      declare area[cnt]
      declare norec[cnt]
      SELE 2
      GO TOP
      LOCATE FOR SUPP_CODE=SUPPCOD .AND. .NOT. ORDR_PRINT .AND. .NOT. EOF()
      DO WHILE .T.
         IF FOUND()
            PONU=ORDER_NBER
            @  3, 31 SAY 'PO #. : '+STR(PONU)
            ITM=ITM+1
            VAR1=STR(INT(ITM),2)
            VAR2=subst(DRUG_NAME,1,15)
            VAR3=SUBS(DRUG_TYPE,1,9)
            VAR4=SUBS(BUY_UNIT,1,7)
            VAR5=TRANS(QANT_PURCH,'9,999')
            VAR6=TRANS(U_PR_PURCH,'99,999,999.99')
            IF DISC_PURCH<>0
               VAR7=TRANS(DISC_PURCH,"99.99")+"%"
            ELSE
               VAR7=SPAC(6)
            ENDIF
            VAR8=TRANS(NET_PURCH,"99,999,999.99")
            FILD[ITM]=VAR1+'  '+VAR2+'   '+VAR3+' '+VAR4+' '+VAR5+' '+VAR6+' '+VAR7+' '+VAR8
            AREA[ITM]='2'
            NOREC[ITM]=RECNO()
            TTL=TTL+NET_PURCH
            CONTINUE
            LOOP
         ELSE
            EXIT
         ENDIF
      ENDDO
      SELE 3
      GO TOP
      LOCATE FOR SUPP_CODE=SUPPCOD .AND. .NOT. ORDR_PRINT .AND. .NOT. EOF()
      DO WHILE .T.
         IF FOUND()
            PONU=ORDER_NBER
            @  3, 31 SAY 'PO #. : '+STR(PONU)
            ITM=ITM+1
            VAR1=STR(INT(ITM),2)
            VAR2=subst(DISP_NAME,1,15)
            VAR3=SUBS(DISP_TYPE,1,9)
            VAR4=SUBS(BUY_UNIT,1,7)
            VAR5=TRANS(QANT_PURCH,'9,999')
            VAR6=TRANS(U_PR_PURCH,'99,999,999.99')
            IF DISC_PURCH<>0
               VAR7=TRANS(DISC_PURCH,"99.99")+"%"
            ELSE
               VAR7=SPAC(6)
            ENDIF
            VAR8=TRANS(NET_PURCH,"99,999,999.99")
            FILD[ITM]=VAR1+'  '+VAR2+'   '+VAR3+' '+VAR4+' '+VAR5+' '+VAR6+' '+VAR7+' '+VAR8
            AREA[ITM]='3'
            NOREC[ITM]=RECNO()
            TTL=TTL+NET_PURCH
            CONTINUE
            LOOP
         ELSE
            EXIT
         ENDIF
      ENDDO
      OK=.T.
      DO WHILE OK=.T.
         SET COLO TO W+/B+
         @ 24,0 CLEA TO 24,79
         SET COLO TO W/R
         @ 24,62 SAY 'Esc -> Choice Menu'
         SET COLO TO W/B
         IF TTL<>0
            @ 17,0 TO 17,79
            @ 18, 34 SAY "TOTAL VALUE OF PURCHASE ORDER :"
            @ 18, 66 SAY TTL PICT '999,999,999.99'
            IF MPPN=.T.
               @ 19, 58 SAY 'P.P.N.'
               VALPPN=10/100*TTL
               GRNTTL=TTL+VALPPN
               @ 19, 66 SAY VALPPN PICT '999,999,999.99'
               @ 20, 66 SAY '--------------'
               @ 21, 66 SAY GRNTTL PICT '999,999,999.99'
            ELSE
               @ 19,0 CLEA TO 23,79
            ENDIF
*            @ 22,  0 SAY "PAYMENT DUE  "+LTRIM(STR(PAYTERM,3))+" DAYS AFTER COMPLETE DELIVERY"
*            IF MPPN=.T.
*               @ 23, 0 SAY "NO PAYMENT WILL BE PROCESSED BEFORE SUBMISSION OF FAKTUR PAJAK"
*            ENDIF
         ENDIF
         inkey()
         cari=achoice(10,0,16,79,fild)
         mix=lastkey()
         DO CASE
         CASE MIX=27
            DO WHILE .T.
               SET COLO TO W/R
               @ 24,0 CLEA TO 24,79
               @ 24,4 SAY 'N->Next Supplier ; M->Modify Item ; P->P.P.N ; Esc->Return to Prev. Menu'
               PLH=' '
               @ 24,78 get plh
               read
               IF LASTKEY()=27
                  CLOSE ALL
                  RETURN
               ENDIF
               SET COLO TO W+/B+
               IF .NOT. PLH $ 'NMPnmp'
                  LOOP
               ENDIF
               DO CASE
               CASE PLH='N' .or. PLH='n'
                  OK=.F.
                  EXIT
               CASE PLH='M' .or. PLH='m'
                  OK=.F.
                  DO WHILE .T.
                     PILIH=achoice(10,0,16,79,fild)
                     MX=LASTKEY()
                     DO CASE
                     CASE MX=13
                        DAERAH=AREA[PILIH]
                        RECNUM=NOREC[PILIH]
                        DSPMOD=SAVESCREEN(0,0,24,79)
                        DO PURC_MOD
                        RESTSCREEN(0,0,24,79,DSPMOD)
                        IF TTL<>0
                           @ 17,0 TO 17,79
                           @ 18, 34 SAY "TOTAL VALUE OF PURCHASE ORDER :"
                           @ 18, 66 SAY TTL PICT '999,999,999.99'
                           IF MPPN=.T.
                              @ 19, 58 SAY 'P.P.N.'
                              VALPPN=10/100*TTL
                              GRNTTL=TTL+VALPPN
                              @ 19, 66 SAY VALPPN PICT '999,999,999.99'
                              @ 20, 66 SAY '--------------'
                              @ 21, 66 SAY GRNTTL PICT '999,999,999.99'
                           ELSE
                              @ 19,0 CLEA TO 23,79
                           ENDIF
*                           @ 22,  0 SAY "PAYMENT DUE  "+LTRIM(STR(PAYTERM,3))+" DAYS AFTER COMPLETE DELIVERY"
*                           IF MPPN=.T.
*                              @ 23, 0 SAY "NO PAYMENT WILL BE PROCESSED BEFORE SUBMISSION OF FAKTUR PAJAK"
*                           ENDIF
                        ENDIF
                     CASE MX=27
                        EXIT
                     ENDCASE
                  ENDDO
               CASE PLH='P' .or. PLH='p'
                  OK=.T.
                  IF MPPN=.T.
                     PPNYN='Y'
                  ELSE
                     PPNYN='N'
                  ENDIF
                  DO WHILE .T.
                     @ 23,0 CLEA TO 23,79
                     @ 23,0 SAY 'P.P.N. (Y/N) ? ' GET PPNYN
                     READ
                     IF .NOT. PPNYN $ 'YN'
                        LOOP
                     ELSE
                        EXIT
                     ENDIF
                  ENDDO
                  IF PPNYN='Y'
                     MPPN=.T.
                  ELSE
                     MPPN=.F.
                  ENDIF
                  SELE 1
                  IF REC_LOCK()
                     REPL PPN WITH MPPN
                  ENDIF
                  UNLOCK
                  EXIT
               ENDCASE
            ENDDO
         OTHER
            LOOP
         ENDCASE
      ENDDO
      SELE 1
      CONTINUE
      LOOP
   ELSE
      CLOSE DATA
      CLOSE INDEX
      RETURN
   ENDIF
ENDDO




*Formatted by: Herman T Ver. 7.1  on May 31, 1996.
